#include <iostream>
#include <string>
#include <boost/asio.hpp>
#include "server.h"
#include "router.h"
#include "nettop_run.h"
#include "controller.h"
// ---------------

int main() {

    try {
//        // Check command line arguments.
//        if (argc != 4)
//        {
//            std::cerr << "Usage: http_server <address> <port> <doc_root>\n";
//            std::cerr << "  For IPv4, try:\n";
//            std::cerr << "    receiver 0.0.0.0 80 .\n";
//            std::cerr << "  For IPv6, try:\n";
//            std::cerr << "    receiver 0::0 80 .\n";
//            return 1;
//        }

        //-------------------------------------------------------------------------------------------
        // 以借用的方式将单例nettop_mgr对象传入到cap线程
        //std::thread cap_th(&nettop::cap_mgr::async_cap, &nettop::nettop_mgr::Instance().c,
        //                   std::ref(nettop::nettop_mgr::Instance().p_list), std::ref(nettop::quit));
        //cap_th.detach();
        //-------------------------------------------------------------------------------------------

        //-------------------------------------------------------------------------------------------
        // 加载路由层
        router::node http_router;
        http_router.addRoute("/hello",controller::hello);
        //http_router.addRoute("/net/top",controller::net_top);
        http_router.addRoute("/peer/log/parser",controller::peer_log_parser_handler);
        //-------------------------------------------------------------------------------------------

        // Initialise the server.
        http::server::server s("0.0.0.0", "8080", "/home/ct/workspace/httpserver",http_router);
        // Run the server until stopped.
        s.run();
    }
    catch (std::exception &e) {
        std::cerr << "exception: " << e.what() << "\n";
    }

    return 0;
}
